﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model.Response;
using RestSharp;
using WebApiDemo.Models;

namespace InvokDemo
{
    public partial class InvokApiDemo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RestRequest request = new RestSharp.RestRequest(RestSharp.Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddBody(
                new { KEY = "eba28190-0bd2-434b-82aa-0d57df73f8e6" });

            request.Resource = "TestService/getAllUser";
            request.AddHeader("Content-Type", "application/json;charset=UTF-8");
            //request.AddHeader("Content-Type", "application/json;charset=GB2312");
            RestClient client = new RestClient();
            //client.BaseUrl = "http://192.168.2.2:2020/";
            client.BaseUrl = "http://www.godsuper.com/";
            //client.BaseUrl = "http://localhost:15007/";
            RestResponse rsp = (RestResponse)client.Execute(request);

            var userList = Newtonsoft.Json.JsonConvert.DeserializeObject<Rsp_GetUsers>(rsp.Content);
            DataTable dt=new DataTable();
            dt.Columns.Add("ID", typeof (string));
            dt.Columns.Add("名字", typeof(string));
            dt.Columns.Add("地址", typeof(string));
            foreach (var item in userList.list)
            {
                DataRow dr = dt.NewRow();
                dr["ID"] = item.Id;
                dr["名字"] = item.Name;
                dr["地址"] = item.Msg;
                dt.Rows.Add(dr);
            }
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
    }
}